/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.mikepenz.actionitembadge.library.utils;

import ohos.agp.colors.RgbColor;
import ohos.agp.components.AttrHelper;
import ohos.agp.components.Text;
import ohos.app.Context;

/**
 * 杂项工具
 *
 * @since 2021-04-10
 */
public class Misc {
    private Misc() {
    }

    /**
     * 判断字符序列是否为空
     *
     * @param cs 字符序列
     * @return 是否为空
     */
    public static boolean isEmpty(CharSequence cs) {
        return cs == null || cs.length() == 0;
    }

    /**
     * 判断数组是否为空
     *
     * @param array 数组
     * @param <T> 数组类型
     * @return 是否为空
     */
    public static <T> boolean isEmpty(T[] array) {
        return array == null || array.length == 0;
    }

    /**
     * 颜色类型转换
     *
     * @param rgbColor rgb颜色对象
     * @return util 颜色对象
     */
    public static ohos.agp.utils.Color toUtilsColor(RgbColor rgbColor) {
        return new ohos.agp.utils.Color(rgbColor.asArgbInt());
    }

    /**
     * 尺寸转像素
     *
     * @param type 尺寸类型
     * @param value 尺寸值
     * @param context context
     * @return 像素值
     */
    public static int sizeToPx(Text.TextSizeType type, int value, Context context) {
        int px;

        switch (type) {
            case FP:
                px = AttrHelper.fp2px(value, context);
                break;
            case VP:
                px = AttrHelper.vp2px(value, context);
                break;
            case PX:
            default:
                px = value;
                break;
        }

        return px;
    }
}
